<template>
  <div>
    首页
    <el-table :data="cutObj.records" stripe style="margin-bottom: 20px" border>
      <el-table-column prop="name" label="电影名"></el-table-column>
      <el-table-column prop="price" label="价格"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" @click="add(scope.row)">下单</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--    分页-->
    <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        background
        layout="prev, pager, next, jumper"
        :total="this.cutObj.total"
        @current-change="cutAll"
    />

    <el-button type="success" @click="findAll">刷新</el-button>
  </div>

</template>
<script>
import axios from "axios";
import {ElMessage} from 'element-plus'

export default {
  data() {
    return {
      cutObj: {},
      loginUser: {},
      currentPage: '',
      pageSize: 3,
    }
  },
  methods: {
    add(obj) {
      if (this.loginUser != undefined) {
        axios.get("/project/sale/buy", {params: obj}).then(n => {

              if (n.data == "ok") {

                ElMessage({
                  message: '下单成功',
                  type: 'success',
                })
                this.cutAll(1);
              } else {
                ElMessage({
                  message: '下单失败',
                  type: 'success',
                })

              }
            }
        )


      } else {
        this.$router.push("/view/login")
      }


    },
    findAll() {
      axios.get("/project/sale/moviesBeanList").then(n => {
        if (n.data == "ok") {
          ElMessage({
            message: '刷新成功',
            type: 'success',
          })
          this.cutAll(1);
        }

      })

    }, cutAll(pageNO) {
      this.currentPage = pageNO;

      console.log(pageNO);
      axios.get("/project/sale/cutAll", {params: {pageNO: pageNO}}).then(n => {
        this.cutObj = n.data;
      })


    }

  },
  created() {
    this.cutAll(1);
    this.loginUser = JSON.parse(sessionStorage.getItem("loginUser"));
  }
}
</script>

<style scoped>

</style>